package me.wpf.model;

import lombok.Data;

/**
 * Description: 单元格
 *
 * @author 王朋飞
 * @create 2019/8/13
 */
@Data
public class HBaseCell implements Comparable<HBaseCell> {
    /**
     * 列簇：列名
     */
    protected String field;
    /**
     * 单元格的值
     */
    protected String fieldvalue;
    /**
     * 时间戳（版本号）
     */
    protected Long capTime;

    public HBaseCell(String field, String fieldvalue, Long capTime) {
        this.field = field;
        this.fieldvalue = fieldvalue;
        this.capTime = capTime;
    }

    /**
     * 比较值和列是否相同
     *
     * @param o
     * @return
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        HBaseCell cell = (HBaseCell) o;
        if (field.equals(cell.field) && fieldvalue.equals(cell.fieldvalue)) {
            if (capTime > cell.capTime) {
                cell.setCapTime(capTime);
            }
            return true;
        }
        return false;
    }

    @Override
    public int hashCode() {
        return this.field.hashCode() + 31 * this.fieldvalue.hashCode();
    }


    /**
     * 按照时间戳比较大小
     *
     * @param o
     * @return
     */
    @Override
    public int compareTo(HBaseCell o) {
        return o.getCapTime().compareTo(this.capTime);
    }
}
